package com.paopao.loansheet.mapper;

import com.paopao.domain.EmployeeBean;
import com.paopao.domain.ItemInfoBean;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

public class MySqlprovider {
    public String getListSql(Map<String, Object> map){
        EmployeeBean employeeBean = (EmployeeBean) map.get("searchBean");
        StringBuilder sql = new StringBuilder("select id, name, sex, employee_no as employeeNo, age, position, post_level as postLevel," +
                " create_time as creatTime, update_time as updateTime, status from swans_employee_info").
                append(" where 1=1");
        if(!StringUtils.isEmpty(employeeBean.getPosition())){
            sql.append(" and position=#{employeeBean.position}");
        }
        if(!StringUtils.isEmpty(employeeBean.getName())){
            sql.append(" and name=#{employeeBean.name}");
        }
        if(employeeBean.getStatus() != null ){
            sql.append(" and status=#{employeeBean.status}");
        }

        if(employeeBean.getSex() != null ){
            sql.append(" and sex=#{employeeBean.sex}");
        }

        return sql.toString();
    }
    public String getItemListSql(Map<String, Object> map){
        ItemInfoBean itemInfoBean = (ItemInfoBean) map.get("searchBean");
        StringBuilder sql = new StringBuilder("select project_name as projectName, project_no as projectNo, standard, scale, type, create_time as createTime, " +
                "update_time as updateTime, status from swans_project").
                append(" where 1=1");
        if(itemInfoBean.getType() != null ){
            sql.append(" and status=#{itemInfoBean.type}");
        }

        if(itemInfoBean.getStatus() != null ){
            sql.append(" and status=#{itemInfoBean.status}");
        }
        return sql.toString();
    }
}
